#pragma once


class KRBaseTextureD3D9 : public VRTexture, public VAllocator
{
public:
	virtual ~KRBaseTextureD3D9(void)
	{
	}
	virtual void DeleteThis() {
		VDelete this;
	}
	virtual IDirect3DSurface9* GetDepthSurface()
	{
		return NULL;
	}
#if !VFINAL
	virtual void SetProfileName(const char* Name)
	{

	}
#endif 

};

typedef VSmartPtr<KRBaseTextureD3D9> KRBaseTextureD3D9Ptr;

class KRTextureD3D9 : public KRBaseTextureD3D9
{
	
	enum
	{
		TEXTURE_2D,
		TEXTURE_3D,
		TEXTURE_ARRAY,
		TEXTURE_CUBE,
	};
#if !VFINAL
	virtual void SetProfileName(const char* Name)
	{
		if (m_Texture)
		{
			m_Texture->SetPrivateData(WKPDID_D3DDebugObjectName, Name, strlen(Name), 0 );
			IDirect3DSurface9* Surface;
			m_Texture->GetSurfaceLevel(0, &Surface);
			if (Surface)
			{
				Surface->SetPrivateData(WKPDID_D3DDebugObjectName, Name, strlen(Name), 0 );
				Surface->Release();
			}
		}
	}
#endif 
public:
	static inline KRTextureD3D9* CreateTexture2D(IDirect3DDevice9* Dev, UINT Width, UINT Height, EVRPixelFormat Format,UINT NumMips, UINT Flags)
	{
		D3DFORMAT D3DFormat = VenusToD3D(Format);
		return CreateTexture2D(Dev, Width, Height, D3DFormat, NumMips, Flags);
	}
	static KRTextureD3D9* CreateTexture2D(IDirect3DDevice9* Dev, UINT Width, UINT Height, D3DFORMAT Format,UINT NumMips, UINT Flags);

	static inline KRTextureD3D9* CreateTextureCube(IDirect3DDevice9* Dev, UINT Width, EVRPixelFormat Format,UINT NumMips, UINT Flags)
	{
		D3DFORMAT D3DFormat = VenusToD3D(Format);
		return CreateTextureCube(Dev, Width, D3DFormat, NumMips, Flags);
	}
	static KRTextureD3D9* CreateTextureCube(IDirect3DDevice9* Dev, UINT Width, D3DFORMAT Format,UINT NumMips, UINT Flags);

	inline KRTextureD3D9(IDirect3DTexture9* Tex):m_Texture(Tex),m_DepthSurface(NULL){}
	virtual ~KRTextureD3D9(void)
	{
		if (m_Texture)
		{
			m_Texture->Release();
		}
	}
	inline void InitDepthSurface()
	{
		VASSERT(m_Texture);
		m_Texture->GetSurfaceLevel(0, &m_DepthSurface);
	}
	virtual IDirect3DSurface9* GetDepthSurface()
	{
		return m_DepthSurface;
	}
	IDirect3DTexture9* m_Texture;
	IDirect3DSurface9* m_DepthSurface;
};

typedef VSmartPtr<KRTextureD3D9> KRTextureD3D9Ptr;

